<?php

namespace web\user\controller;

/**
 * 后台首页
 */
class Index extends Base {
    
    public function index() {
        // //用户等级分布图
        $accountM = new \addons\member\model\MemberAccountModel();
        //今日开始
        $start_time = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m'), date('d'), date('Y')));
        //今日结束
        $end_time = date('Y-m-d H:i:s',mktime(23, 59, 59 , date('m'), date('d'), date('Y')));
        //会员总人数
        $account_count = $accountM->count();
        $this->assign('account_count',$account_count);
        //今日注册人数
        $today_reg_count =  $accountM->where(['register_time' => ['between', [$start_time , $end_time]]])->count();
        $this->assign('today_reg_count',$today_reg_count);
        //USDT积分总数 元气豆积分总数
        $configM = new \addons\config\model\BalanceConf();
        $balanceM = new \addons\member\model\Balance();
        $type_list = $configM->getDataList(-1, -1, 'is_show=1', 'id,name', 'id asc');
        foreach ($type_list as $key => &$value) {
            $value['amount'] = $balanceM->where(['type' => $value['id']])->sum('amount');
        }
        $this->assign('asset_amount', $type_list);
        $this->assign('is_admin', $this->is_admin);
        //提现统计
        $withoutM = new \addons\order\model\Without();
        $with_today =  $withoutM->where(['add_time' => ['between', [$start_time , $end_time]]])->sum('amount');
        $this->assign('with_today',$with_today);
        $recordM = new \addons\member\model\TradingRecord();
        $static_today =  $recordM->where(['type'=>10,'update_time' => ['between', [$start_time , $end_time]]])->sum('amount');
        $dymic_today =  $recordM->where(['type'=>11,'update_time' => ['between', [$start_time , $end_time]]])->sum('amount');
        $this->assign('static_today',$static_today);
        $this->assign('dymic_today',$dymic_today);
        return $this->fetch();
    }

    public function edit_pwd() {
        if (IS_POST) {
            $m = new \web\common\model\user\AccountModel();
            $id = $this->login_user_id;
            $password1 = trim($_POST['password1']);
            $password = trim($_POST['password']);
            if ($password != $password1) {
                return $this->failData('两次输入的密码不符');
            }
            $accountData['id'] = $id;
            $accountData['password'] = md5($password);
            $ret = $m->save($accountData);
            session('loginData', '');
            return $this->successData();
        } else {
            $this->assign('username', $this->login_user_name);
            $this->assign('id', '');
            return $this->fetch();
        }
    }
    
    public function clear_cache(){
        dump($this->globalCache->clearAll());
    }

}
